<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let state;
      let setState;

      function useState(initialState) {
        if (!state) {
          state = initialState;
        }

        function dispatch(newState) {
          state = newState;
          // 模拟重新渲染
          render();
        }

        setState = dispatch;
        return [state, dispatch];
      }

      function render() {
        const [count, setCount] = useState(0);
        console.log('Render:', count);

        // 模拟点击事件
        setTimeout(() => {
          setCount(count + 1);
        }, 1000);
      }

      render();
    </script>
  </body>
</html>
